package com.alan.mr;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * 排序
 * Created by Alan on 2017/10/2.
 */
public class SortHot extends WritableComparator{

    public SortHot() {
        super(KeyPair.class,true);
    }

    /**
     * 按照年份升序排序，同时每一年中温度降序排序。
     * @param a
     * @param b
     * @return
     */
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        KeyPair o1 = (KeyPair) a;
        KeyPair o2 = (KeyPair) b;
        //默认是升序的
        int res = Integer.compare(o1.getYear(),o2.getYear());
        if(res != 0){
            return res;
        }
        return -Integer.compare(o1.getHot(),o2.getHot());//降序排序
    }
}
